package br.bovino.usuario;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.bovino.R;

public class UsuarioListAdapter extends BaseAdapter{
	private LayoutInflater inflater;
	private List<Usuario> lista;
	
	public UsuarioListAdapter(Context context, List<Usuario> lista){
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.lista = lista;
	}
	public int getCount(){
		return lista.size();
	}
	
	public Object getItem(int position){
		return lista.get(position);
	}
	
	public long getItemId(int position){
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent){
		//recupera o Usuario da posicao atual
		Usuario u = lista.get(position);
		View view = inflater.inflate(R.layout.usuario_linha_tabela, null);
		//atualiza o valor do TextView
		TextView nome = (TextView) view.findViewById(R.id.txtNome);
		nome.setText(u.nome);
		TextView usuario = (TextView) view.findViewById(R.id.txtUsuario);
		nome.setText(u.usuario);
		TextView senha = (TextView) view.findViewById(R.id.txtSenha);
		nome.setText(u.senha);		
		return view;
	}
}
